#!/usr/bin/python
# -*- coding: utf-8 -*-

from config.cnf import LOG_CONFIG 
import logging

def initlog():
    logger = None
    logger = logging.getLogger()
    hdlr = logging.FileHandler(LOG_CONFIG['FILENAME'])
    formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(LOG_CONFIG['LEVEL'])
    return [logger, hdlr]

def debug(msg):
    logger, hdlr = initlog()
    logger.debug(msg)
    logger.removeHandler(hdlr)

def info(msg):
    logger, hdlr = initlog()
    logger.info(msg)
    logger.removeHandler(hdlr)

def error(err):
    logger, hdlr = initlog()
    msg = str(err.args[0]) + ':' + err.args[1]
    logger.error(msg)
    logger.removeHandler(hdlr)
